package com.song.flowable.controller;

import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.DeploymentBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * 流程定义
 */
@RestController
public class ProcessDefinitionController {
    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    ProcessEngineConfiguration processEngineConfiguration;

    /**
     * 流程定义手动部署
     * @throws Exception
     */
    @RequestMapping("/add")
    public void add() throws Exception {
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        File file = new File("D:\\song\\gitee\\spring-flowable\\src\\main\\resources\\processes\\ask_for_leave.bpmn20.xml");
        InputStream inputStream = new FileInputStream(file);
        deploymentBuilder.addInputStream("ask_for_leave.bpmn20.xml", inputStream);
        deploymentBuilder.deploy();
    }
}
